package top.zkh.login;

import java.io.IOException;
import java.sql.Connection;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.swing.JOptionPane;
import com.java1234.dao.managerDao;
import com.java1234.model.Manager;
import com.java1234.util.DbUtil;
import com.java1234.util.StringUtil;

public class managerServlet extends HttpServlet{
	private DbUtil dbUtil = new DbUtil();
	private managerDao managerDao = new managerDao();
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		req.setCharacterEncoding("UTF-8");//修改接收到的请求的编码格式
		resp.setContentType("text/html; charset=UTF-8");//修改发送请求的编码格式
		//从前台的页面拿值，通过表单的name属性
		String managername = req.getParameter("managerName");
		String managerpassword = req.getParameter("managerPassword");
		if(StringUtil.isEmpty(managername)) {
			return;
		}
		if(StringUtil.isEmpty(managerpassword)) {
			req.getRequestDispatcher("error.jsp").forward(req, resp);
			return;
		}
		Manager manager = new Manager(managername,managerpassword);
		Connection con = null;
		try {
			con = dbUtil.getCon();
			Manager currentUser=managerDao.login(con, manager);
			req.getRequestDispatcher("managerinter.jsp").forward(req, resp);

			} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			}finally {
				try {
				dbUtil.closeCon(con);
				} catch (Exception e) {
				// TODO Auto-generated catch block
					e.printStackTrace();
					}
				}
		}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		this.doGet(req, resp);
	}
}
